<?php
require './config/config_bd.php';

$uname = $_REQUEST["name"];

$sql =        " select id, name, ind_main_assign from assign_vw ";
$sql = $sql . " where id_users = get_user_id( :uname )";
$sql = $sql . " order by ind_main_assign desc, id desc";
try {
    $dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
	
	$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	$stmt = $dbh->prepare($sql);  
	$stmt->bindParam("uname", $uname);	
	$stmt->execute();
	$dates = $stmt->fetchAll(PDO::FETCH_OBJ);
	$dbh = null;
	echo '{"items":'. json_encode($dates) .'}'; 
} catch(PDOException $e) {
	echo '{"error":{"text":'. $e->getMessage() .'}}'; 
}

?>